﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace SignalBox.Core.Model
{
    public class Train
    {

        public enum TrainState
        {
            NOT_AVAILABLE,
            WAITING_SIGNAL,
            ACCELERATING,
            BRAKING,
            RUNNING,
            STOPPED,
            LEFT
        }


        private List<TrainStop> stops = new List<TrainStop>();

        private List<TrackCell> movementHistory;

        public Train()
        {
            CurrentDirection = DIRECTION.INVALID;
            State = TrainState.NOT_AVAILABLE;
            AcceleratingSpeed = 0.5;
            BrakingSpeed = 0.6;
            Acceleration = 0.0;
            CurrentSpeedRestriction = Double.MaxValue;
            Length = 300;

            movementHistory = new List<TrackCell>();
        }

        public double CurrentSpeedRestriction
        {
            get;
            set;
        }

        public double AcceleratingSpeed
        {
            get;
            set;
        }

        public double BrakingSpeed
        {
            get;
            set;

        }

        public TrainStop NextStop
        {
            get
            {
                foreach (TrainStop ts in Stops)
                {
                    if (!ts.Passed)
                        return ts;
                }
                return null;
            }
        }

        public List<TrainStop> Stops
        {
            get { return stops; }
        }

        public string TrainCode
        {
            get;
            set;
        }

        public int MaxSpeed
        {
            get;
            set;
        }

        public double CurrentSpeed
        {
            get;
            set;
        }

        public Point HeadLocation
        {
            get;
            set;
        }

        public Point TailLocation
        {
            get;
            set;
        }

        public DIRECTION CurrentDirection
        {
            get;
            set;
        }

        public TrainState State
        {
            get;
            set;
        }

      

        public double DistanceTravelledCurrentCell
        {
            get;
            set;
        }
        public double Acceleration
        {
            get;
            set;
        }

        public List<TrackCell> MovementHistory
        {
            get
            {
                return movementHistory;
            }
        }

        public int Length
        {
            get;
            set;
        }
    }
}
